﻿//-----------------------------------------------------------------------
// <copyright file="WorldManager.cs" company="Minecraft Tools Project">
//      Copyright Laurie Tutton. All Rights Reserved
// </copyright>
//-----------------------------------------------------------------------

namespace Minecraft.Imaging
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// This class is the main entry point for the imaging library. It handles the main bulk of rendering things.
    /// </summary>
    public class WorldManager : IMapRenderer
    {
        /// <summary>
        /// Renders the chunks in the map
        /// </summary>
        /// <param name="settings">The settings to render with</param>
        /// <returns>the rendered chunks in an image</returns>
        public System.Drawing.Image RenderMap(IMapSettings settings)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Renders the chunks within the area in chunk coordinates
        /// </summary>
        /// <param name="updateArea">The rectangle to update</param>
        /// <param name="settings">The settings to render with</param>
        /// <returns>The rendered chunks in an image</returns>
        public System.Drawing.Image RenderMapArea(Rectangle updateArea, IMapSettings settings)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Recursively looks up all .mcr files inside a folder
        /// </summary>
        /// <param name="settings">The settings for the current render</param>
        /// <param name="folder">The starting folder</param>
        /// <returns>A list of region files</returns>
        private List<string> GetFolder(IMapSettings settings, string folder)
        {
            List<string> files = new List<string>();
            foreach (string directory in Directory.GetDirectories(folder))
            {
                if (settings.IsHell && directory.Substring(directory.LastIndexOf('\\') + 1).StartsWith("DIM-"))
                {
                    files.AddRange(this.GetFolder(settings, directory));
                }
                else if (!settings.IsHell && !directory.Substring(directory.LastIndexOf('\\') + 1).StartsWith("DIM-"))
                {
                    files.AddRange(this.GetFolder(settings, directory));
                }
            }

            foreach (string fileItem in Directory.GetFiles(folder, "*.mcr"))
            {
                files.Add(fileItem);
            }

            return files;
        }
    }
}